package com.leetcode.algorithm.y22.m07.w4;

import java.util.ArrayDeque;
import java.util.Deque;

/**
 * 155. 最小栈
 * 
 * https://leetcode.cn/problems/min-stack/
 * 
 * @author jie.deng
 *
 */
class MinStack {

	private Deque<Integer> stack;
	private Deque<Integer> minStack;

	public MinStack() {
		stack = new ArrayDeque<>();
		minStack = new ArrayDeque<>();
	}

	public void push(int val) {
		stack.push(val);
		if (minStack.isEmpty() || minStack.peek() > val) {
			minStack.push(val);
		} else {
			minStack.push(minStack.peek().intValue());
		}
	}

	public void pop() {
		stack.pop();
		minStack.pop();
	}

	public int top() {
		return stack.peek().intValue();
	}

	public int getMin() {
		return minStack.peek().intValue();
	}
}